package org.feidao.chapter91.service;

import lombok.extern.slf4j.Slf4j;
import org.feidao.chapter91.elasticSearch.DocumentUtil;
import org.feidao.chapter91.domain.Heroic;
import org.feidao.chapter91.elasticSearch.IndexUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by linghufeixia on 2022-11-8.
 */
@Slf4j
@Service
public class HeroicService {
    @Autowired
    IndexUtil indexUtil;
    @Autowired
    DocumentUtil documentUtil;

    public void createIndex(String index){
        indexUtil.createIndex(index);
    }

    public void updateHeroic(Heroic heroic, String index,String id){
        documentUtil.updateDocument(heroic, index, id);
    }

    public void insertHeroic(Heroic heroic, String index,String id){
        documentUtil.addDocument(heroic, index, id);
    }

    public void deleteHeroic(String index, String id) {
        documentUtil.deleteDocument(index,id);
    }

    public String selectHeroic(String index, String id){
        return documentUtil.getDocumnet(index, id).getSourceAsString();
    }
}
